// 复制文本到剪切板
const copyToClipboard=(text)=>navigator.clipboard.writeText(text)
copyToClipboard('你好')

// 获取某个日期位于当前的第几天
const dayOfYear = (date)=>Math.floor((date-new Date(date.getFullYear(),0,0))/1000/60/60/24);
dayOfYear(new Date(2022,10,27));//331

// 把rgb验证转换成一个灰色
const gray =(r,g,b)=>0.2126*r+0.7152*g+0.0722*b;
gray(50,100,150)//92.98

// 解析url中的参数
const parseQuery=(url)=>{
    q={}
    url.replace(/([^?&=]+)=([^&]+)/g,(_,k,v)=>(q[k]=v));
    return q
}
parseQuery('http://a.com/?a=1&b=2')//{a:1,b=2}
parseQuery('a=1&b=2')//{a:1,b=2}

// 筛选对象属性
const pick = (obj,...props)=>Object.fromEntries(Object.entries(obj).filter(([k])=>props.includes(k)));

pick({a:1,b:2,c:3},'a','b')//{a:1,b:2}

// 随机颜色
const randomColor = ()=>'#'+Math.floor(Math.random()*0xffffff).toString(16).padEnd(4,'0');
randomColor();

// 随机字符串
const randomString = ()=>Math.random().toString(36).slice(2);
randomString();


// 去掉字符串中的元素标签
const removeTag = (fragment)=>new DOMParser().parseFromString(fragment,'text/html').body.textContent||'';
removeTag(`<div>Hello Wolrd</div>`);


